在 Git 中,並行開發是透過分支實現的。正式來說, 分支是一條獨立的開發路徑 它會從主時間軸分叉出來。這使得多條工作線可以共存為 內部物件 而不影響主代碼庫的穩定性。
1. 原初狀態:主分支(Master)
每個倉儲一開始都會有一個預設分支,稱為 master。這是 Git 的預設分支。當您執行 git branch 來列出所有分支時,其旁邊的 星號 (*) 代表目前正處於檢出狀態的環境——也就是您當前活躍的開發宇宙。
2. 功能分支
雖然有些分支存在時間較短,但一個 功能分支 是一種持續時間較長的主題分支,專門為了開發特定功能而建立。這能將「進行中的工作」代碼與已準備就緒的「主分支」隔離開來。
類比說明: 想像主建築圖紙是摩天大樓的設計藍圖。要測試太陽能板時,你可以使用透明疊層(功能分支)。你可以在疊層上自由實驗和犯錯,完全不會危及原始藍圖的完整性。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
Which command is used to list all branches in a Git repository?
git list
git branch
git checkout --list
git show-branches
✅ Correct!
Correct! Running 'git branch' displays all local branches in the current repository.❌ Incorrect
The command 'git branch' is the standard utility for listing, creating, and deleting branches.QUESTION 2
What does the asterisk (*) next to a branch name in the branch list signify?
The branch has uncommitted changes.
The branch is protected and cannot be deleted.
The branch is currently checked out (active).
The branch is the newest one created.
✅ Correct!
Exactly. The asterisk indicates your current location (HEAD) within the project's development universes.❌ Incorrect
The asterisk is a status marker indicating which branch is 'active' or 'checked out'.QUESTION 3
How is a 'feature branch' defined in Git development?
A branch that only contains CSS files.
A temporary branch that is never merged.
A longer-running topic branch for a specific functionality.
The branch where all bugs are fixed globally.
✅ Correct!
Yes! Feature branches are used to isolate specific tasks until they are ready for the main codebase.❌ Incorrect
Feature branches are intended for developing specific features in isolation from the main timeline.QUESTION 4
What is the name of Git's default development branch?
mainline
trunk
master
root
✅ Correct!
Correct. 'master' is the default name Git assigns to the first branch created in a repository.❌ Incorrect
While some modern platforms use 'main', Git's internal default and the focus of this tutorial is 'master'.QUESTION 5
True or False: A branch is considered an 'internal object' that tracks specific changes.
True
False
✅ Correct!
True. Branches are abstractions—internal pointers to commits that allow for parallel development.❌ Incorrect
Git manages branches as internal references (pointers) to specific points in the commit history.Architectural Design Simulation
Managing Parallel Blueprints
You are leading a project to design a skyscraper. You have the 'master' blueprints finalized up to the 50th floor. Your client wants to see two options: a rooftop garden and a rooftop helipad. You decide to use Git branching logic to handle this request.
Q
If you create a branch for the 'rooftop-garden', what happens to the 'master' blueprints while you work on the garden design?
Solution:
The master blueprints remain unchanged and stable. The garden design exists in an independent line of development, ensuring the original project history is not compromised.
The master blueprints remain unchanged and stable. The garden design exists in an independent line of development, ensuring the original project history is not compromised.
Q
Which specific branch type would the 'rooftop-garden' be categorized as?
Solution:
It would be a feature branch (or topic branch), created with the intention of developing a specific piece of functionality (the garden) in isolation.
It would be a feature branch (or topic branch), created with the intention of developing a specific piece of functionality (the garden) in isolation.
Q
How would you verify which 'blueprint' (branch) you are currently drawing on using the Git CLI?
Solution:
You would use the 'git branch' command. The branch name with the asterisk (*) next to it represents the currently checked-out environment.
You would use the 'git branch' command. The branch name with the asterisk (*) next to it represents the currently checked-out environment.